﻿namespace TestService_FS

open System
open JAAM.RPC

type CustomString() =
    member val str = "" with get,set    

type SimpleTests() as this= 
    inherit RPCServiceBase()

    [<RpcMethod ("internal.echo")>]
    member this.HandleEcho (s:string) = s

    [<RpcMethod("error1")>]
    member this.devideByZero (s:string) = 
        let i = 0
        let j = 15;
        s + (j/i).ToString() 

    [<RpcMethod("error2")>]
    member this.thowsException (s:string) (ex : RpcException ref) =
        ex := RpcException(-1, "This exception was thrown using: ref JsonRpcException", null)
        s

    [<RpcMethod("error3")>]
    member this.throwsException2 (s:string) =
        raise (RpcException(-27000, "This exception was thrown using: throw new JsonRpcException()", null))
        s

    [<RpcMethod("error4")>]
    member this.throwsException3 (s:string) =
        //JsonRpcContext.SetException (JsonRpcException(-27000, "This exception was thrown using: JsonRpcContext.Current().SetException()", null))
        s

    [<RpcMethod>]
    member this.RequiresCredentials (magicKey:string) = "Passed Authentication"

    [<RpcMethod>]
    member this.testDateTime() =  DateTime.Now

    [<RpcMethod>]
    member this.testFloat (input:float) = input

    [<RpcMethod>]
    member this.testSingle (input:Single) = input

    [<RpcMethod>]
    member this.testInt (input:int) = ["one";"two";"three";input.ToString()]

    [<RpcMethod>]
    member this.testSimpleString (input:string) = ["one";"two";"three";input]

    [<RpcMethod>]
    member this.testCustomString (input:CustomString) = ["one";"two";"three";input.str]

    [<RpcMethod("add")>]
    member this.add (l:double) (r:double) = l + r

    [<RpcMethod>]
    member this.NullableFloatToNullableFloat (a:Nullable<float>) = a

    [<RpcMethod>]
    member this.DecimalToNullableDecimal (x:decimal) = Nullable<decimal> x

    [<RpcMethod>]
    member this.StringToListOfString (input:string) = ["one";"two";"three";input]

    [<RpcMethod>]
    member this.StringToThrowingExcpetion (input:string) = 
        raise (Exception("Throwing Exception"))
        ["one";"two";"three";input]

    [<RpcMethod>] member this.IntToInt (input:int) = input
    [<RpcMethod>] member this.Int32ToInt32 (input:int32) = input
    [<RpcMethod>] member this.Int16ToInt16 (input:int16) = input
    [<RpcMethod>] member this.Int64ToInt64 (input:int64) = input

